package day_2022_12_to_3.year2023;

/**
 * @author haomin
 * @date 2023/03/02 22:11
 **/
public class Day3_3_offer0502 {
    class Solution {
        public String printBin(double num) {
            StringBuilder sb = new StringBuilder();
            sb.append("0.");
            for (int i = 0; i < 32; i++) {
                num = num * 2;
                if (num >= 1) {
                    num -= 1;
                    sb.append(1);
                } else {
                    sb.append(0);
                }
                if (num == 0) {
                    break;
                }
            }
            if (num != 0) {
                return "ERROR";
            }
            return sb.toString();
        }
    }
}